// 压缩字符串 (模拟)
class Solution {
public:
    string compressString(string param) {
        string ret;
        int n = param.size();
        for (int l = 0; l < n; l++)
        {
            char ch = param[l];
            ret += ch;
            int r = l;
            while (r + 1 < n && param[r] == param[r + 1]) r++;
            if (r - l + 1 > 1) ret += to_string(r - l + 1);
            l = r;
        }
        return ret;
    }
};

// chika和蜜柑 (topK)
// 1.
#include <iostream>
#include <queue>
using namespace std;

using pii = pair<int, int>;

struct cmp{
    bool operator()(const pii& p1, const pii& p2)
    {
        if (p1.first == p2.first) return p1.second > p2.second;
        else return p1.first < p2.first;
    }
};

const int N = 2e5 + 10;
using ll = long long;
priority_queue<pii, vector<pii>, cmp> pq;
int n, k;
int a[N], b[N];
ll suma, sumb;

int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++)
        pq.push({b[i], a[i]});
    while (k--)
    {
        sumb += pq.top().first;
        suma += pq.top().second;
        pq.pop();
    }
    cout << suma << " " << sumb << endl;
    return 0;
}

// 2.
#include <iostream>
#include <algorithm>
using namespace std;

using pii = pair<int, int>;
const int N = 2e5 + 10;
pii arr[N];
int n, k;

int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> arr[i].first;
    for (int i = 0; i < n; i++) cin >> arr[i].second;
    sort(arr, arr + n, [&](const pii& p1, const pii& p2){
        if (p1.second == p2.second) return p1.first < p2.first;
        else return p1.second > p2.second;
    });
    long s = 0, t = 0;
    for (int i = 0; i < k; i++)
    {
        s += arr[i].second;
        t += arr[i].first;
    }
    cout << t << " " << s << endl;
    return 0;
}

//  01背包
class Solution {
public:
    int knapsack(int V, int n, vector<vector<int> >& vw) {
        vector<int> dp(V + 1);
        for (int i = 0; i < n; i++)
            for (int j = V; j >= vw[i][0]; j--)
                dp[j] = max(dp[j], dp[j - vw[i][0]] + vw[i][1]);
        return dp[V];
    }
};